package exception;

import java.util.ConcurrentModificationException;
import org.testng.annotations.Test;

public class Exception1 {

    @Test
    public void t1() {
        try {
            throwException2();
        } catch (ArithmeticException e) {
            System.out.println("捕捉到了");
        }
    }

    @Test
    public void t2() {
        try {
            throwException2();
        } catch (Exception e) {
            System.out.println("捕捉到了");
        }
    }


    @Test
    public void t3() {
        // 无法捕获异常
        try {
            throwException2();
        } catch (NullPointerException e) {
            System.out.println("捕捉到了");
        }
    }

    @Test
    public void t4() {
        try {
            int s = 1 / 0;
        } catch (Exception e){
            // 会打印异常堆栈
            e.printStackTrace();
        }
    }

    @Test
    public void t5() {
        try {
            int s = 1 / 0;
        } catch (Exception e){
            // 不会打印异常堆栈
        }
    }

    /**
     * 结果和t4相同
     */
    @Test
    public void t6() {
        System.out.println(1 / 0);
    }

    public static void main(String[] args) {

        try {
            throwException2();
        } catch (ArithmeticException e) {
            System.out.println("捕捉到了");
        }

        System.out.println(System.getProperties());


//        try {
//            throwException();
//        } catch (Exception e) {
//            if (e instanceof ConcurrentModificationException) {
//                System.out.println(e);
//                System.out.println("捕捉到了");
//            }
//        }

    }

    public static void throwException() throws Exception {
        int i = 1 / 0;
    }

    public static void throwException2(){
        int i = 1 / 0;
    }

}
